$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/user/authInfo/list',
        datatype: "json",
        colModel: [			
			{ label: '账号', name: 'mobile', index: 'mobile', width: 80 },
			{ label: '昵称', name: 'nick', index: 'nick', width: 80 },
			{ label: '认证状态', name: 'authStatusDesc', index: 'auth_status_desc', width: 80 },
			{ label: '姓名', name: 'realName', index: 'real_name', width: 80 },
			{ label: '身份证号', name: 'idNo', index: 'id_no', width: 80 },
			{ label: '身份证正面', name: 'idUrl', index: 'id_url', width: 80,formatter: function(value, options, row){
					var title = "身份证正面";
				return "<img  style='width:30px;height: 30px;cursor:pointer;'  src='"+value+"' " +
					"onclick='showImg(\""+value+"\",\""+title+"\")'></img>";
			}},
			{ label: '身份证反面', name: 'idBackUrl', index: 'id_back_url', width: 80 ,formatter: function(value, options, row){
					var title = "身份证反面";
					return "<img  style='width:30px;height: 30px;cursor:pointer;'  src='"+value+"' " +
						"onclick='showImg(\""+value+"\",\""+title+"\")'></img>";
				}}
		],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
		beforeProcessing: function(data, status, xhr) {
			// 假设我们检查名为"errorField"的字段
			if (data.code !== 0) {
				// 如果满足条件，则显示错误消息
				alert(data.msg);
				// 停止处理，不显示数据
				return false;
			}
			// 如果没有错误，继续处理数据
			return true;
		},
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

function showImg(val,tit){
	$("#showImg").attr("src",val);
	layer.open({
		type: 1,
		skin: 'layui-layer-molv',
		title: tit,
		area: ['650px', '500px'],
		shade: 0,
		shadeClose: false,
		content: jQuery("#Img"),
		btn: ['确定'],
		btn1: function (index) {
			layer.close(index);
		}
	});


}

var vm = new Vue({
	el:'#rrapp',
	data:{
        q:{
            name: null,
			authStatus: null
        },
		showList: true,
		title: null,
		auth: {},
		dict: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.dict = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "审核";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			const url= "sys/user/authAudit";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.auth),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "sys/dict/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "sys/user/authInfo/"+id, function(r){
                vm.dict = r.data;
                vm.auth.id = r.data.id;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'name': vm.q.name,"authStatus":vm.q.authStatus},
                page:1
            }).trigger("reloadGrid");
		}
	}
});